package com.example.constellation.starfrag;

import android.content.Intent;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.example.constellation.R;
import com.example.constellation.bean.StarInfoBean;
import com.example.constellation.util.AssetsUtil;
import de.hdodenhof.circleimageview.CircleImageView;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class StarAnalysisActivity extends AppCompatActivity {
    TextView titleTv;
    ImageView backIv;
    CircleImageView iconIv;
    TextView nameTv,dateTv;
    ListView analysisLv;
    StarInfoBean.StarinfoBean bean;
    private Map<String, Bitmap> contentlogoImgMap;
    private TextView footerTv;//listview底部布局需要改变的textview

    List<StarAnalysisBean> mDatas;
    private AnalyslsBaseAdapter adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_star_analysis);
        Intent intent=getIntent();
        bean=(StarInfoBean.StarinfoBean) intent.getSerializableExtra("star");
        init();
        mDatas=new ArrayList<>();//初始化显示在listview的数据源
        adapter=new AnalyslsBaseAdapter(this,mDatas);
        analysisLv.setAdapter(adapter);
        addData();//添加数据 到集合中
    }

    /**
     * 加载数据到list当中
     */
    private void  addData(){
        StarAnalysisBean sab1 =new StarAnalysisBean("性格特点：",bean.getTd(),R.color.darkblue);
        StarAnalysisBean sab2 =new StarAnalysisBean("掌管宫位：",bean.getGw(),R.color.lightpink);
        StarAnalysisBean sab3 =new StarAnalysisBean("显阴阳性：",bean.getYy(),R.color.darkgreen);
        StarAnalysisBean sab4 =new StarAnalysisBean("最大特征：",bean.getTz(),R.color.purple);
        StarAnalysisBean sab5 =new StarAnalysisBean("主管星球：",bean.getZg(),R.color.orange);
        StarAnalysisBean sab6 =new StarAnalysisBean("幸运颜色：",bean.getYs(),R.color.lightred);
        StarAnalysisBean sab7 =new StarAnalysisBean("搭配珠宝：",bean.getZb(),R.color.grey);
        StarAnalysisBean sab8 =new StarAnalysisBean("幸运号码：",bean.getHm(),R.color.colorAccent);
        StarAnalysisBean sab9 =new StarAnalysisBean("相配金属：",bean.getJs(),R.color.colorPrimary);
        mDatas.add(sab1);mDatas.add(sab2);mDatas.add(sab3);mDatas.add(sab4);mDatas.add(sab5);
        mDatas.add(sab6);mDatas.add(sab7);mDatas.add(sab8);mDatas.add(sab9);
        //数据变化，显示适配器更新
        adapter.notifyDataSetChanged();
    }
    //初始化
    private void init(){
        titleTv=findViewById(R.id.title_tv);
        backIv=findViewById(R.id.title_iv_back);
        iconIv=findViewById(R.id.staranalysis_iv);
        nameTv=findViewById(R.id.staranalysis_tv_name);
        dateTv=findViewById(R.id.staranalysis_tv_date);
        analysisLv=findViewById(R.id.staranalysis_lv);

        //为listview添加底部布局
        View footerView=LayoutInflater.from(this).inflate(R.layout.footer_star_analysis,null);
        analysisLv.addFooterView(footerView);
        footerTv=footerView.findViewById(R.id.footerstar_tv_info);
        titleTv.setText("星座详情");
        //返回上一级点击事件
        backIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        nameTv.setText(bean.getName());
        dateTv.setText(bean.getDate());
        contentlogoImgMap=AssetsUtil.getContentlogoImgMap();
        Bitmap bitmap=contentlogoImgMap.get(bean.getLogoname());
        iconIv.setImageBitmap(bitmap);
        footerTv.setText(bean.getInfo());
    }
}
